package com.code.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.code.dao.FffMapper;
import com.code.dao.BbbMapper;
import com.code.entity.PageResult;
import com.code.entity.QueryPageBean;
import com.code.pojo.Address;
import com.code.pojo.Fff;
import com.code.pojo.Bbb;
import com.code.service.FffService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service
public class FffServiceImpl implements FffService {

    @Autowired
    FffMapper fffMapper;
    @Autowired
    BbbMapper productMapper;


    @Override
    public PageResult<Fff> findPage(QueryPageBean queryPageBean) {
     PageHelper.startPage(queryPageBean.getPage(),queryPageBean.getSize());
        List<Fff> fffList = fffMapper.findLike(queryPageBean);
        PageInfo<Fff> pageInfo = new PageInfo<>(fffList);
        PageResult<Fff> result = new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
        return result;

    }
//    @Override
//    public PageResult<Fff> findPage(Fff fff) {
//     PageHelper.startPage(fff.getPage(),fff.getSize());
//        List<Fff> fffList = fffMapper.findLike(fff);
//        PageInfo<Fff> pageInfo = new PageInfo<>(fffList);
//        PageResult<Fff> result = new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
//        return result;
//    }



    @Override
    public Fff findById(Integer id) {
        return fffMapper.selectByPrimaryKey(id);
    }

    @Override
    public void add(Fff fff) {
        fffMapper.insert(fff);
    }

    @Override
    public void update(Fff fff) {
        fffMapper.updateByPrimaryKeySelective(fff);
    }

    @Override
    public void delete(Integer id) {
        fffMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Bbb> findAddress() {
        return productMapper.selectAll();
    }


    //   统计用注解写Sql语句 字段名称为 name  value
    @Override
    public List<Map> tongji() {
        return fffMapper.tongji();
    }

//    @Override
//    public List<Map> twobzt() {
//        return fffMapper.twobzt();
////        return null;
//    }

    @Override
    public PageResult<Fff> findPageNo(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getPage(),queryPageBean.getSize());
        List<Fff> fffList = fffMapper.findPageNo(queryPageBean);
        PageInfo<Fff> pageInfo = new PageInfo<>(fffList);
        PageResult<Fff> result = new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
        return result;
    }

    @Override
    public void editState(Integer id) {
        Fff fff = fffMapper.selectByPrimaryKey(id);
        fff.setState(1);
        fffMapper.updateByPrimaryKeySelective(fff);
    }
}
